layui.use(['form', 'layedit', 'laydate'], function () {
    var form = layui.form
        , layer = layui.layer
        , $ = layui.jquery
        , layedit = layui.layedit
        , laydate = layui.laydate;

    $.get("/getAccount",{},function(result) {
        $("#updateBy").val(result.username);
    });

    laydate.render({
        elem: '#createTime'
    });


    laydate.render({
        elem: '#updateTime'
    });


    form.verify({

        merchantNo: function (value) {
            if (value.length > 10) {
                return '长度不能大于10';
            }
            if (value.length == "") {
                return '必填项不能为空';
            }
        },

        name: function (value) {
            if (value.length > 100) {
                return '长度不能大于100';
            }
            if (value.length == "") {
                return '必填项不能为空';
            }
        },

        accId: function (value) {
            if (value.length > 64) {
                return '长度不能大于64';
            }
            if (value.length == "") {
                return '必填项不能为空';
            }
        },




        remarks: function (value) {
            if (value.length > 2000) {
                return '长度不能大于2000';
            }
        },

    });
    //监听提交
    form.on('submit(formDemo)', function (data) {
        $ = layui.jquery;
        layer = layui.layer;
        var waitIndex = '';

        $.ajax({
            url: "/newmerchantservice/merchantController/update",
            type: "POST",
            data: data.field,
            dataType: 'json',
            beforeSend: function () {
                waitIndex = layer.load();//删除前打开遮挡层
            },
            success: function (returnData) {
                if (returnData.code == 500) {
                    layer.msg(returnData.message, {icon: 2, time: 1500, shade: 0.1}, function () {
                    });

                } else {
                    layer.msg(returnData.message, {icon: 1, time: 1500, shade: 0.1}, function () {
                        top.winui.window.close('edit');
                    });

                }


            }, complete: function () {
                layer.close(waitIndex);
            }
        });

        return false;
    });
});